<template>
  <div>
    <el-table v-loading="loading" tooltip-effect="darkTable" :data="dealServicingPlanList" border height="280">
      <el-table-column :label="$t('投资主体')" align="center" prop="investmentName" />
      <el-table-column :label="$t('预计还款日期')" align="center" prop="expectDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.expectDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('预计还款金额') + $t('金额单位')" align="center" prop="expectMoney" width="130">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.expectMoney, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('收款状态')" align="center" prop="status" :formatter="statusFormat" width="150" />
    </el-table>
  </div>
</template>
<script>
import { listDealServicingPlan } from '@/api/deal/servicing/dealServicingPlan'
  export default {
    name: 'DealServicingPlanInfo',
    props: {
      // 公司ID
      bussId: {
        type: String,
        required: true
      },
      isComponent: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 指标监控表格数据
        dealServicingPlanList: [],
        // 查询参数
        queryParams: {
          dealId: this.bussId,
          pageNum: 1,
          pageSize: 10
        },
        // 表单参数
        form: {},
        // 收款状态字典
        statusOptions: [],
        // 类型字典
        typeOptions: []
      }
    },
    created() {
      // 还款状态字典
      this.getDicts('repayment_status').then(response => {
        this.statusOptions = response.data
      })
      // 类型字典
      this.getDicts('servicing_plan_type').then(response => {
        this.typeOptions = response.data
      })
      this.getList()
    },
    methods: {
      statusFormat(row) {
        return this.selectDictLabel(this.statusOptions, row.status)
      },
      typeFormat(row) {
        return this.selectDictLabel(this.typeOptions, row.type)
      },
      getList() {
        this.loading = true
        this.queryParams.dealId = this.bussId
        if (this.isComponent) {
          this.queryParams.pageNum = null
          this.queryParams.pageSize = null
        }
        listDealServicingPlan(this.queryParams).then(response => {
          var arr = response.rows.filter(item => item.investmentName !== null && item.investmentName !== undefined && item.investmentName !== '')
          this.dealServicingPlanList = arr
          this.loading = false
        })
      }
    }
  }
</script>
